const app = getApp();
import grace from "../../../utils/grace.js";

grace.page({
  /**
   * 页面的初始数据
   */
  data: {
    school_name: '',
    attendance_date: '',
    attendances: [],
    total: {}
  },
  onLoad(){
    let that = this;
    let d = new Date();
    that.$data = {
      'school_name': wx.getStorageSync('school_name'),
      'class_id': wx.getStorageSync('class_id'),
      'class_name': wx.getStorageSync('class_name'),
      'attendance_date': d.getFullYear() + '年' + (d.getMonth() + 1) + "月" + d.getDate() + '日'
    }
    that.getList();
  },
  getList() {
    let that = this;
    let school_id = wx.getStorageSync('school_id')

    wx.showLoading({
      title: '加载中...',
    })
    let url = app.globalData.api + '/api/v1.0/report/attendance/' + school_id;
    that.$http.get(url, { token: wx.getStorageSync('token') }).then((res) => {
      if (res.data.code == 0) {
        that.$data.total = res.data.total;
        that.$data.attendances = res.data.data;
      } else if (res.data.code == 10001) {
        wx.navigateTo({
          url: "/pages/common/authorize/index"
        })
      }else {
        that.$data.attendances = [];
      }
      wx.hideLoading();
    }).catch(err => {
      console.log(err.status, err.message);
    });
  },
})